package StudyCode.summary.mydatetime;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class Flight {
	public static void main(String[] args) {
		DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM d yyyy  hh:mm a");

		// 从 JANUARY 20, 2019, at 7:30 p.m. 离开旧金山
		LocalDateTime leaving = LocalDateTime.of(2019, Month.JANUARY, 20, 19, 30);
		ZoneId leavingZone = ZoneId.of("America/Los_Angeles");
		ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);

		try {
			String out1 = departure.format(format);
			System.out.printf("离开: %s (%s)%n", out1, leavingZone);
		} catch (DateTimeException exc) {
			throw exc;
		}

		// 飞行时间 10小时 50 钟, 或者 650 分钟
		ZoneId arrivingZone = ZoneId.of("Asia/Tokyo");
		ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusMinutes(650);

		try {
			String out2 = arrival.format(format);
			System.out.printf("到达: %s (%s)%n", out2, arrivingZone);
		} catch (DateTimeException exc) {
			throw exc;
		}

	}
}
